<?php
/**
 * 更新数据结构
 **/
$biaoming = 'huodong';
$prefix = \Phpcmf\Service::M()->prefix;
$rows = \Phpcmf\Service::M('Module')->table($prefix.'module')->where('dirname', $biaoming)->getRow();
// 3.0.6 圈子id
$biao = $prefix.'1_'.$biaoming;
if (\Phpcmf\Service::M()->db->tableExists($biao) && !\Phpcmf\Service::M()->db->fieldExists('quanid', $biao)) {
    \Phpcmf\Service::M()->query('ALTER TABLE `'.$biao.'` ADD `quanid` int(10) NOT NULL COMMENT \'圈子ID\'');
}
if (\Phpcmf\Service::M()->db->tableExists($biao) && !\Phpcmf\Service::M()->db->fieldExists('tieid', $biao)) {
    \Phpcmf\Service::M()->query('ALTER TABLE `'.$biao.'` ADD `tieid` int(10) NOT NULL COMMENT \'贴子ID\'');
}
$quanid = \Phpcmf\Service::M()->table($prefix.'field')->where('relatedname', 'module')->where('relatedid', $rows['id'])->where('fieldname', 'quanid')->counts();
if (!$quanid) {
	\Phpcmf\Service::M()->db->table('field')->insert(array(
		'name' => '圈子ID',
		'fieldname' => 'quanid',
		'fieldtype' => 'Text',
		'relatedid' => $rows['id'],
		'relatedname' => 'module',
		'isedit' => '1',
		'ismain' => '1',
		'issystem' => '0',
		'ismember' => '1',
		'issearch' => '0',
		'disabled' => '0',
		'setting' => 
		dr_array2string(array (
		  'option' => 
		  array (
			'fieldtype' => '',
			'fieldlength' => '',
			'value' => '',
			'width' => '',
			'css' => '',
		  ),
		  'validate' => 
		  array (
			'xss' => '1',
			'required' => '0',
			'pattern' => '',
			'errortips' => '',
			'check' => '',
			'filter' => '',
			'tips' => '',
			'formattr' => '',
		  ),
		  'is_right' => '0',
		)),
		'displayorder' => '0',
	));
}
$tieid = \Phpcmf\Service::M()->table($prefix.'field')->where('relatedname', 'module')->where('relatedid', $rows['id'])->where('fieldname', 'tieid')->counts();
if (!$tieid) {
	\Phpcmf\Service::M()->db->table('field')->insert(array(
		'name' => '贴子ID',
		'fieldname' => 'tieid',
		'fieldtype' => 'Text',
		'relatedid' => $rows['id'],
		'relatedname' => 'module',
		'isedit' => '1',
		'ismain' => '1',
		'issystem' => '0',
		'ismember' => '1',
		'issearch' => '0',
		'disabled' => '0',
		'setting' => 
		dr_array2string(array (
		  'option' => 
		  array (
			'fieldtype' => '',
			'fieldlength' => '',
			'value' => '',
			'width' => '',
			'css' => '',
		  ),
		  'validate' => 
		  array (
			'xss' => '1',
			'required' => '0',
			'pattern' => '',
			'errortips' => '',
			'check' => '',
			'filter' => '',
			'tips' => '',
			'formattr' => '',
		  ),
		  'is_right' => '0',
		)),
		'displayorder' => '0',
	));
}